﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace LimpaGaragem.DAO.User
{
    public class UserFlagged
    {
        /// <summary>
        /// Return list of user flagged from user
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.User.UserFlagged> GetListOfUserFlaggedFromUser(int IDUser)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_USER", IDUser));
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR007_ListUserFlaggedFrom", 0, objListOfParameters);

                List<LimpaGaragem.Model.User.UserFlagged> objListOfUserFlagged = new List<LimpaGaragem.Model.User.UserFlagged>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.User.UserFlagged objUserFlagged = new LimpaGaragem.Model.User.UserFlagged();
                    objUserFlagged.IDUser = IDUser;
                    objUserFlagged.ID = Convert.ToInt32(objDataRow["ID_USER_FLAGGED"]);
                    objUserFlagged.IDUserFlagged = Convert.ToInt32(objDataRow["ID_USER_FLAG"]);
                    objUserFlagged.Content = objDataRow["DS_CONTENT"].ToString();
                    objUserFlagged.DateTimeInserted = Convert.ToDateTime(objDataRow["DT_INC"]);
                    objListOfUserFlagged.Add(objUserFlagged);
                }
                return objListOfUserFlagged;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Return list of user flagged to user
        /// </summary>
        /// <returns></returns>
        public List<LimpaGaragem.Model.User.UserFlagged> GetListOfUserFlaggedToUser(int IDUser)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_USER", IDUser));
                DataTable objDataTable = objDataAccess.ReturnDataTable(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR007_ListUserFlaggedTo", 0, objListOfParameters);

                List<LimpaGaragem.Model.User.UserFlagged> objListOfUserFlagged = new List<LimpaGaragem.Model.User.UserFlagged>();
                foreach (DataRow objDataRow in objDataTable.Rows)
                {
                    LimpaGaragem.Model.User.UserFlagged objUserFlagged = new LimpaGaragem.Model.User.UserFlagged();
                    objUserFlagged.IDUserFlagged = IDUser;
                    objUserFlagged.ID = Convert.ToInt32(objDataRow["ID_USER_FLAGGED"]);
                    objUserFlagged.IDUser = Convert.ToInt32(objDataRow["ID_USER"]);
                    objUserFlagged.Content = objDataRow["DS_CONTENT"].ToString();
                    objUserFlagged.DateTimeInserted = Convert.ToDateTime(objDataRow["DT_INC"]);
                    objListOfUserFlagged.Add(objUserFlagged);
                }
                return objListOfUserFlagged;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Insert new user flagged
        /// </summary>
        public int InsertUserFlagged(int IDUserFlag,
                            int IDUser,
                            string Content)
        {
            try
            {
                Framework.DataAccess objDataAccess = new Framework.DataAccess();

                //PARAMETERS
                List<SqlParameter> objListOfParameters = new List<SqlParameter>();
                objListOfParameters.Add(new SqlParameter("@ID_USER_FLAG", IDUserFlag));
                objListOfParameters.Add(new SqlParameter("@ID_USER", IDUser));
                objListOfParameters.Add(new SqlParameter("@DS_CONTENT", Content));

                //EXECUTE
                return objDataAccess.ExecuteQueryAndReturnValue(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, Framework.DataAccess.QueryType.Procedure, "PR007_InsertUserFlagged", 0, objListOfParameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
